﻿using Infrastructure.Excel;
using Infrastructure.Web;
using MyData.Dto;
using MyWeb.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyWeb.Controllers
{
    public class NewRecordController : BaseController
    {
        // GET: NewRecord
        [HandlerLogin]
        public ActionResult NewRecordIndex()
        {
            return View();
        }
        public ActionResult GetNewAccessRecord(QueryListModel query, string NickName,string StartDate, string EndDate)
        {
            DateTime startDate = DateTime.Parse(StartDate).Date;
            DateTime endDate = DateTime.Parse(EndDate).Date;
            var result = AccessRecordApp.GetNewAccessRecord(query, NickName,startDate,endDate);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public FileResult ExcelImport()
        {

            List<CheckRecordDto> checkInDtos = Session["Data"] as List<CheckRecordDto>;
            if (checkInDtos == null) checkInDtos = new List<CheckRecordDto>();
            string filename = $"~/Export/{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
            filename = Server.MapPath(filename);
            EpplusHelper.SaveToExcel(checkInDtos, filename);
            return File(filename, "application/octet-stream", $"{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls");

        }
    }
}